
/**
\file
Definition of the sun::time class.
\author Sean Tromans
*/

#ifndef	SUN_TIME_HPP
#define	SUN_TIME_HPP

#include <boost/cstdint.hpp>
#include <sun/lua/lua_fwd.hpp>

namespace sun
{

	/**
	Represents a time difference in both millisecons and seconds.
	\author Sean Tromans
	*/
	class time
	{
		//
		//	Public Member Functions
		//
		public:

			/**
			Default constructor.
			\author Sean Tromans
			*/
			time( );

			/**
			Construct time from a milliseconds value.
			@param ms The time to become.
			\author Sean Tromans
			*/
			time( boost::int32_t ms );

			/**
			Construct time from a seconds value.
			@param s The time to become.
			\author Sean Tromans
			*/
			time( float s );

			/**
			Gets the number of milliseconds in this time.
			\author Sean Tromans
			*/
			boost::int32_t milliseconds( ) const
			{
				return m_milliseconds;
			}

			/**
			Sets the number of milliseconds in this time and recalculates the seconds value.
			@param ms The time to become.
			\author Sean Tromans
			*/
			void milliseconds( boost::int32_t ms );

			/**
			Gets the number of seconds in this time.
			\author Sean Tromans
			*/
			float seconds( ) const
			{
				return m_seconds;
			}

			/**
			Sets the number of seconds in this time and recalculates the milliseconds value.
			@param s The time to become.
			\author Sean Tromans
			*/
			void seconds( float s );

			/**
			Assigns a value to a time object from a millisecond value.
			@param ms The time to become.
			\author Sean Tromans
			*/
			time & operator = ( boost::int32_t ms );

			/**
			Assigns a value to a time object from a second value.
			@param s The time to become.
			\author Sean Tromans
			*/
			time & operator = ( float s );

		//
		//	Private Member Variables
		//
		private:

			boost::int32_t	m_milliseconds;
			float			m_seconds;

		//
		//	Static Member Functions
		//
		public:

			/**
			Exposes the time class to the lua state.
			@param L The lua_State being initialised.
			\author Sean Tromans
			*/
			static void lua_interface( lua_State * L );
	};

	/**
	Test for equality between two time objects.
	@param lhs The first time object to test.
	@param rhs The second time object to test.
	@return True if the two times are equal. (Uses the millisecond values to avoid floating point innaccuracies.)
	\author Sean Tromans
	*/
	bool operator == ( time const & lhs, time const & rhs );

	/**
	Test for inequality between two time objects.
	@param lhs The first time object to test.
	@param rhs The second time object to test.
	@return True if the two times are not equal. (Uses the millisecond values to avoid floating point innaccuracies.)
	\author Sean Tromans
	*/
	bool operator != ( time const & lhs, time const & rhs );

};

#endif	//SUN_TIME_HPP
